<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "order_goods".
 *
 * @property int $id 订单商品关系ID
 * @property string $order_no 订单编号
 * @property int $goods_id 商品ID
 * @property string $goods_no 商品编号
 * @property string $goods_name 商品名称
 * @property int $first_cate 商品类型
 * @property int $have_package 0没有套餐 1套餐
 * @property int $seller_id 商家ID
 * @property string $seller 商家名称
 * @property int $buyer_id 买家ID
 * @property string $buyer 买家名称
 * @property int $nums 购买数量
 * @property int $status 订单状态
 * @property int $invitor_id 邀请人ID
 * @property string $install_price 安装维护费
 * @property string $price 商品单价
 * @property string $price_total 总价
 * @property int $region_1 省ID
 * @property int $region_2 市ID
 * @property int $region_3 地级市ID
 * @property int $time_begin 订单开始时间
 * @property int $time_end 订单结束时间
 * @property int $addtime 添加时间
 */
class OrderGoods extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'order_goods';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['order_no', 'goods_id', 'goods_no', 'goods_name', 'first_cate', 'seller_id', 'seller', 'buyer_id', 'buyer', 'status', 'addtime'], 'required'],
            [['order_no', 'goods_id', 'goods_no', 'seller_id', 'buyer_id', 'nums', 'invitor_id', 'region_1', 'region_2', 'region_3', 'time_begin', 'time_end', 'addtime'], 'integer'],
            [['install_price', 'price', 'price_total'], 'number'],
            [['goods_name'], 'string', 'max' => 150],
            [['first_cate'], 'string', 'max' => 5],
            [['have_package'], 'string', 'max' => 2],
            [['seller', 'buyer'], 'string', 'max' => 100],
            [['status'], 'string', 'max' => 3],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '订单商品关系ID',
            'order_no' => '订单编号',
            'goods_id' => '商品ID',
            'goods_no' => '商品编号',
            'goods_name' => '商品名称',
            'first_cate' => '商品类型',
            'have_package' => '0没有套餐 1套餐',
            'seller_id' => '商家ID',
            'seller' => '商家名称',
            'buyer_id' => '买家ID',
            'buyer' => '买家名称',
            'nums' => '购买数量',
            'status' => '订单状态',
            'invitor_id' => '邀请人ID',
            'install_price' => '安装维护费',
            'price' => '商品价格',
            'price_total' => '总价',
            'region_1' => '省ID',
            'region_2' => '市ID',
            'region_3' => '地级市ID',
            'time_begin' => '订单开始时间',
            'time_end' => '订单结束时间',
            'addtime' => '添加时间',
        ];
    }
    
    
    public static function getNoPackageGoodsByOrderNo($order_no){
        $sql = "select id,first_cate,goods_id,buyer_id,have_package,nums from order_goods where order_no=$order_no and have_package=0";
        $command = \Yii::$app->db->createCommand($sql);
        return $command->queryAll();
    }
    
    public static function getOrderGoodsByOrderNo($order_no){
        $sql = "select id,first_cate,goods_id,goods_no,status,buyer_id,seller_id,have_package,nums,time_end,invitor_id,price,install_price,price_total from order_goods where order_no=$order_no";
        $command = \Yii::$app->db->createCommand($sql);
        return $command->queryAll();
    }
}
